package cn.edu.nchu.fragmentdemo.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.edu.nchu.fragmentdemo.R;
import cn.edu.nchu.fragmentdemo.bean.RouteTask;
import cn.edu.nchu.fragmentdemo.utils.DateConverter;


/**
 * @author Tsuki
 */
public class RouteTaskAdapter extends BaseRecyclerViewAdapter<RouteTask> {


    private OnDeleteClickLister mDeleteClickListener;
    private OnCustomButtonClickListener mCustomButtonClickListener;

    public RouteTaskAdapter(Context context, List<RouteTask> data,boolean hasmore) {
        super(context, data, R.layout.item_normal,hasmore);
    }

    @Override
    protected void onBindData(ItemViewHolder holder, RouteTask bean, int position) {
        View view = holder.getView(R.id.tv_delete);
        view.setTag(position);
        if (!view.hasOnClickListeners()) {
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mDeleteClickListener != null) {
                        mDeleteClickListener.onDeleteClick(v, (Integer) v.getTag());
                    }
                }
            });
        }

        View customButton = holder.getView(R.id.all);
        customButton.setTag(position);
        customButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mCustomButtonClickListener != null) {
                    mCustomButtonClickListener.onCustomButtonClick(v, (Integer) v.getTag());
                }
            }
        });
        ImageView imageView = (ImageView) holder.getView(R.id.item_normal_imageView);
        imageView.setImageResource(R.drawable.uav_route_task);
        ((TextView) holder.getView(R.id.route_task_id)).setText(bean.getId().toString());
        ((TextView) holder.getView(R.id.item_normal_title)).setText(bean.getTaskName());
        String updateTimeStr = DateConverter.toDateString(bean.getUpdateTime());
        ((TextView) holder.getView(R.id.item_normal_update_time)).setText(updateTimeStr);
        ((TextView) holder.getView(R.id.item_normal_location)).setText(bean.getLocation());

    }

    public void setOnDeleteClickListener(OnDeleteClickLister listener) {
        this.mDeleteClickListener = listener;
    }

    public interface OnDeleteClickLister {
        void onDeleteClick(View view, int position);
    }


    public interface OnCustomButtonClickListener {
        void onCustomButtonClick(View view, int position);
    }

    public void setOnCustomButtonClickListener(OnCustomButtonClickListener listener) {
        this.mCustomButtonClickListener = listener;
    }


}
